package b1.scenes.home
{
	import b1.utils.*;
	
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;

	public class BackgroundSwitcher extends Sprite
	{
		private var currentBackground:Sprite;
		
		public function BackgroundSwitcher(background:Sprite)
		{
			super();
			currentBackground = background;
//			currentBackground.width = BFont.stageWidth;
//			currentBackground.height = BFont.stageHeight;
			addChild(currentBackground);
		}
		
		public function switchBackground(background:Sprite, duration:Number):void
		{
			var oldBackground:Sprite = this.currentBackground;
			this.currentBackground = background;
			TweenLite.to(oldBackground, duration, {x:-BFont.stageWidth, y:0, onComplete:onSwitchComplete, onCompleteParams:[oldBackground]});
//			background.width = BFont.stageWidth;
//			background.height = BFont.stageHeight;
			addChild(background);
			TweenLite.from(background, duration, {x:BFont.stageWidth, y:0});
		}
		
		public function onSwitchComplete(oldBackground:Sprite):void
		{
			if (null != oldBackground)
				removeChild(oldBackground);
		}
	}
}